package com.lineage.server.datatables.lock;

import com.lineage.server.datatables.sql.GamblingTable;
import com.lineage.server.datatables.storage.GamblingStorage;
import com.lineage.server.templates.L1Gambling;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class GamblingReading {
  private final Lock _lock = new ReentrantLock(true);
  
  private final GamblingStorage _storage = (GamblingStorage)new GamblingTable();
  
  private static GamblingReading _instance;
  
  public static GamblingReading get() {
    if (_instance == null)
      _instance = new GamblingReading(); 
    return _instance;
  }
  
  public void load() {
    this._lock.lock();
    try {
      this._storage.load();
    } finally {
      this._lock.unlock();
    } 
  }
  
  public L1Gambling getGambling(String key) {
    L1Gambling tmp;
    this._lock.lock();
    try {
      tmp = this._storage.getGambling(key);
    } finally {
      this._lock.unlock();
    } 
    return tmp;
  }
  
  public L1Gambling getGambling(int key) {
    L1Gambling tmp;
    this._lock.lock();
    try {
      tmp = this._storage.getGambling(key);
    } finally {
      this._lock.unlock();
    } 
    return tmp;
  }
  
  public void add(L1Gambling gambling) {
    this._lock.lock();
    try {
      this._storage.add(gambling);
    } finally {
      this._lock.unlock();
    } 
  }
  
  public void updateGambling(int id, int outcount) {
    this._lock.lock();
    try {
      this._storage.updateGambling(id, outcount);
    } finally {
      this._lock.unlock();
    } 
  }
  
  public int[] winCount(int npcid) {
    int[] tmp;
    this._lock.lock();
    try {
      tmp = this._storage.winCount(npcid);
    } finally {
      this._lock.unlock();
    } 
    return tmp;
  }
  
  public int maxId() {
    int tmp;
    this._lock.lock();
    try {
      tmp = this._storage.maxId();
    } finally {
      this._lock.unlock();
    } 
    return tmp;
  }
}
